gCurrentFile = ""
var Main = {
    data() {
        return {
            fileList: null,
            msg: null,
            output: null,
            currentFile: null,
            url: null,

        }
    },
    watch: {
        currentFile: function f() {
            if (this.currentFile) {


            }
        }
    },
    mounted() {
        // this.reload()

    },
    methods: {
        reload() {
            // if (this.currentFile) {
            //     while (true) {
            //         setTimeout(function () {
            //             this.fetchCu()
            //         }, 5000)
            //     }
            //
            // }

        },
        handleChange(file, fileList) {
            this.currentFile = file.name;
        },
        handleRemove(file, fileList) {
            this.fileList = "";
            console.log(file, fileList);
        },
        handlePreview(file) {
            console.log(file);
        },
        handleSuccess(response, file, fileList) {
            this.addMsg(file.name + '上传成功');
            this.currentFile = file.name;
            gCurrentFile = file.name;
            this.url = "http://jmeterreport.k8s.tbocii.tk:8000/" + this.currentFile.split('.')[0] + '/';


            this.output = response.output;//屏幕输出：一般为总计
            this.fetchCu()

        },
        handleReport(name) {
            axios
                .get('/api/html?jobname=' + name)
                .then(response => {
                    let res = response.data;
                    if (res.code === 0) {
                        this.url = res.url;
                         let html='<a href="'+res.url+'" target="_blank">访问报告</a>';
                        this.addMsg("已生成报告请访问->" + html);
                    } else {
                    }


                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        goReport() {
            this.handleReport(gCurrentFile)

        },
        addMsg(txt) {
            let now = getTime();
            this.msg += "<div>" + now + '->' + txt + "</div>"
        },
        fetchCu() {//获取jtl的内容
            // console.log("qingqiu")
            // this.fetchOut(this.currentFile)
        },
        handleKill() {
            axios
                .get('/api/kill')
                .then(response => {
                    let res = response.data;
                    if (res.code === 0) {
                        this.addMsg("已杀掉当前运行的jmeter脚本")
                    } else {
                    }


                })
                .catch(function (error) {
                    console.log(error);
                });
        },
        fetchOut(name) {
            if (name == "null") {
                return
            }
            axios
                .get('/api/output?jobname=' + name)
                .then(response => {
                    let res = response.data;
                    if (res.code === 0) {
                        this.addMsg(this.currentFile + "正在运行ing")
                    } else {
                        this.addMsg(this.currentFile + "运行结束")
                        this.output = res.content;
                    }


                })
                .catch(function (error) {
                    console.log(error);
                });
        }

    },
}
var Ctor = Vue.extend(Main)
var Csheet = new Ctor().$mount('#app')//

function getTime() {     	//获取时间
    var date = new Date();

    var year = date.getFullYear();
    var month = date.getMonth();
    var day = date.getDate();

    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();

    //这样写显示时间在1~9会挤占空间；所以要在1~9的数字前补零;
    if (hour < 10) {
        hour = '0' + hour;
    }
    if (minute < 10) {
        minute = '0' + minute;
    }
    if (second < 10) {
        second = '0' + second;
    }


    var x = date.getDay();//获取星期


    var time = year + '-' + month + '-' + day + '  ' + hour + ':' + minute + ':' + second
    return time
}
